package com.controller;

import com.comm.LogAnno;
import com.model.DaoHang;
import com.model.MyEcharts;
import com.model.MyNode;
import com.model.MyUser;
import com.service.MyuserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api("我的用户")
@RestController
@RequestMapping("/myuser")
public class MyuserController {

    @Autowired
    private MyuserService myuserService ;

    //用户添加方法的对外接口
    @CrossOrigin //解决跨域问题
    @RequestMapping(value = "/addUser" , produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public int addUser (@RequestBody MyUser myUser){
        System.out.println("进入用户添加方法") ;
        return myuserService.addMyUser(myUser);
    }

     //用户修改方法的对外接口
     @CrossOrigin //解决跨域问题
     @RequestMapping(value = "/updateMyuser",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
     public int updateUser (@RequestBody MyUser myUser){
         System.out.println("进入用户修改方法，修改的主键为："+myUser.getUserid());
         return myuserService.updateMyUser(myUser);
     }

    //用户删除方法的对外接口
    @CrossOrigin //解决跨域问题
    @RequestMapping(value = "/deleteMyuser",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public int deleteUser (int userid){
        System.out.println("进入用户删除方法，主键为："+userid);
        return myuserService.deleteMyUser(userid);
    }

    //用户查找方法的对外接口
    @CrossOrigin //解决跨域问题
    @RequestMapping(value = "/getUser",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public MyUser getUser (int userid){
        System.out.println("进入根据主键id进行用户查找方法，主键为："+userid);
        return myuserService.getUser(userid);
    }

    //查询全部用户信息方法的对外接口
    @CrossOrigin //解决跨域问题
    @RequestMapping(value = "/getAll",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyUser> getAll(@RequestBody MyUser myUser){
        System.out.println("进入查询用户全部信息方法");
        System.out.println(myUser.getIp());
        List<MyUser> myUserList=myuserService.getAllMyUsers(myUser);
        System.out.println(myUserList.size());
        return myUserList;
    }

    @CrossOrigin
    @ApiOperation(value = "显示每周的访问趋势")
    @RequestMapping(value="/getTrend",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyEcharts> getTrend(@RequestBody MyUser myUser){
        System.out.println("进入 显示每周的访问趋势 方法");
        List<MyEcharts> myEcharts=myuserService.getTrend(myUser);
        System.out.println(myEcharts.size());
        return myEcharts;
    }

    @CrossOrigin
    @ApiOperation(value = "显示访问次数Top10的IP地址")
    @RequestMapping(value="/getTop10",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyEcharts> getTop10(@RequestBody MyUser myUser){
        System.out.println("进入 显示访问次数Top10的IP地址 方法");
        List<MyEcharts> myEcharts=myuserService.getTop10(myUser);
        System.out.println(myEcharts.size());
        return myEcharts;
    }

    @CrossOrigin
    @ApiOperation(value = "显示1天内访问量的占比情况")
    @RequestMapping(value="/getProportion",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyEcharts> getProportion(@RequestBody MyUser myUser){
        System.out.println("进入 显示1天内访问量的占比情况 方法");
        List<MyEcharts> myEcharts=myuserService.getProportion(myUser);
        System.out.println(myEcharts.size());
        return myEcharts;
    }

    //查询全后10条记录的对外接口
    @CrossOrigin //解决跨域问题
    @RequestMapping(value = "/getLast10",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyUser> getLast10(@RequestBody MyUser myUser){
        System.out.println("进入查询后10条记录方法");

        List<MyUser> myUserList=myuserService.getLast10(myUser);
        System.out.println(myUserList.size());
        return myUserList;
    }

    @LogAnno(OperateType = "添加操作日志")
    @CrossOrigin //解决跨域问题
    @RequestMapping(value="/insertLog",method = RequestMethod.PUT)
    public String insertLog(@RequestBody MyUser myUser){
        System.out.println("进入 通过拦截访问接口的方式写入访问信息 方法");
        return "成功插入日志";
    }


}
